/* __auth__ : KunLin */
package com.cskaoyan.controller.wx;


import com.cskaoyan.bean.User;
import com.cskaoyan.bean.bo.goods.WXGoodsListBO;
import com.cskaoyan.bean.user.SearchHistory;
import com.cskaoyan.bean.vo.goods.*;
import com.cskaoyan.service.CatalogService;
import com.cskaoyan.service.FootprintService;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.SearchHistoryService;
import com.cskaoyan.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("wx/goods")
@RestController
public class WXGoodsController {

    @Autowired
    GoodsService goodsService;

    @Autowired
    FootprintService footprintService;

    @Autowired
    SearchHistoryService searchHistoryService;

    @Autowired
    CatalogService catalogService;
    
    @GetMapping("count")
    public WXGoodsCountVO index(){
        return goodsService.queryGoodsCount();
    }

    @GetMapping("category")
    public WXGoodsCategoryVO category(Integer id){
        return goodsService.queryCategoryStuff(id);
    }


    @GetMapping("list")
    public WXGoodsListVO list(WXGoodsListBO wxGoodsListBO){
//        http://182.92.235.201:8083/wx/goods/list?categoryId=1005011&page=1&limit=10
        //keyword不为空 往搜索历史表中插入数据
        User user = UserUtil.getUser();
        String username = null;
        if(user != null){
            username = user.getUsername();
            if(wxGoodsListBO.getKeyword() != null) {
                searchHistoryService.insertSearchHistory(username,wxGoodsListBO.getKeyword());
            }
        }

        return goodsService.queryListStuff(wxGoodsListBO);
    }


    @GetMapping("detail")
    public WXGoodsDetailVO detail(Integer id){
        footprintService.addFootprint(id);
        return goodsService.queryDetailStuff(id);
    }


    @GetMapping("related")
    public WXGoodsRelatedVO related(Integer id){
        return goodsService.queryRelatedStuff(id);
    }

}
